package com.spa.infrastructure.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class HttpService {

    @Autowired
    private RestTemplate restTemplate;

    public String sendGet(String url, HttpHeaders headers) {
        HttpEntity<Object> entity = new HttpEntity<>(headers);
        ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
        return response.getBody();
    }

    public String sendPost(String url, HttpHeaders requestHeaders, String param) {
        HttpEntity<String> requestEntity = new HttpEntity<>(param, requestHeaders);
        return restTemplate.postForObject(url, requestEntity, String.class);
    }
}
